package com.lry.web.cartoon.controller;

import com.lry.web.cartoon.service.CartoonUpdateService;
import com.lry.web.util.Result;
import com.lry.web.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/cartoonUpdate")
public class CartoonUpdateController {
    @Autowired
    CartoonUpdateService cartoonUpdateService;


    @RequestMapping("/deleteByCartoonId/{cartoonId}")
    @ResponseBody
    public Result deleteByCartoonId(@PathVariable(value = "cartoonId") String cartoonId){
        List<String> list = Arrays.asList(cartoonId.split(","));
        int i = 0;
        for(String id: list){
            i = cartoonUpdateService.deleteByCId(id);
        }
        if(i==0){
            return ResultUtil.error(1,"删除失败");
        }else {
            return ResultUtil.success();
        }
    }
    @RequestMapping("/updateByCartoonId/{cartoonId}")
    @ResponseBody
    public Result updateByCartoonId(@PathVariable(value = "cartoonId") String cartoonId) {
        List<String> list = Arrays.asList(cartoonId.split(","));
        int i = 0;
        for(String id: list){
            i = cartoonUpdateService.updateDeleted(id);
        }
        if(i==0){
            return ResultUtil.error(1,"开启失败");
        }else {
            return ResultUtil.success();
        }
    }


    
}
